package com.panshi.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.panshi.service.ZxService;
import com.panshi.vo.ArticleOk;
import com.panshi.vo.WebResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@CrossOrigin
public class ZxOkController {

    @Autowired
    private ZxService zxService;


    @GetMapping("/zx-ok/list")
    public WebResult findArticle(int page, int limit) {
        WebResult webResult = new WebResult();
        webResult.setCode(0);
        webResult.setData(zxService.findOkArticle(page));
        return webResult;
    }

   /* @GetMapping("/zx-ok/list")
    public List<ArticleOk> findArticle(int page,int limit) throws JsonProcessingException {
        return zxService.findArticle(page);
    }

    @GetMapping("/zx-ok/byid/{id}")
    public ArticleOk findArticleById(@PathVariable Integer id){
        ArticleOk article = zxService.getById(id);
        article.setAReadSum(article.getAReadSum()+1);
        zxService.updateById(article);
        return article;
    }

    @PostMapping("/zx-ok/add")
    public Boolean add(@Validated ArticleOk article){
        return zxService.save(article);
    }

    @GetMapping("/zx-ok/del/{id}")
    public Boolean del(@PathVariable Integer id){
        ArticleOk article = zxService.getById(id);
        article.setAState(-1);
        return zxService.updateById(article);
    }

    @PostMapping("/zx-ok/upd")
    public Boolean upd(@RequestBody ArticleOk article){
        return zxService.updateById(article);
    }

    @PostMapping("/zx-ok/field/{field}/{value}")
    public List<ArticleOk> findArticleByField(@PathVariable String field,@PathVariable Object value){
        return zxService.findArticleByField(field,value);
    }*/
}
